package com.dayaokeji.rhythmschoolstudent.utils;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;

import com.dayaokeji.rhythmschoolstudent.client.common.base.App;

/**
 * Created by Gorden on 2017/9/28.
 */

public class PrefUtils {

    private static final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(App.getAppContext());

    private static final String KEY_LAST_USER_NAME = "key_last_user_name";
    private static final String KEY_IS_FIRST_ALIAS = "key_first_alias";
    private static final String KEY_LAST_JOB_NUMBER = "key_last_job_number";
    private static final String KEY_LAST_PASSWORD = "key_last_password";
    private static final String KEY_NET_TIME_DIFFERENCE = "time_difference";

    private static final String KEY_CHOOSE_THEME_TYPE = "key_choose_theme_type";
    /**
     * 是否第一次显示课程新手引导
     */
    private static final String KEY_IS_FIRST_COURSE_SIGN_SHOW_GUIDE = "key_first_course_sign_guide_view";
    /**
     * 是否第一次显示会议新手引导
     */
    private static final String KEY_IS_FIRST_MEETING_SIGN_SHOW_GUIDE = "key_first_meeting_sign_guide_view";

    private static final String KEY_COLLECT_MOBILE_INFO = "key_collect_mobile_info";

    private static final String KEY_CURRENT_REMOTE_HOST = "key_remote_host";

    private static final String KEY_IS_LOGIN_EASE_IM = "key_ease_im_login";

    private static final String KEY_IS_FIRST_SHOW_IMG = "key_is_first_show_img";

    private static final String KEY_IS_FIRST_AUDIO = "key_is_first_audio";

    private static final String KEY_RANDOM_INT = "random_int";

    private static final String KEY_WEB_NET_DATE = "web_net_date";

    private static final String KEY_PERMISSION_AMOUNT = "key_permission_amount";

    private static final String KEY_EXPIRES_LOGIN_TIME = "key_expires_login";


    public static void setLastUserName(String lastUserName) {
        pref.edit().putString(KEY_LAST_USER_NAME,lastUserName).apply();
    }

    @Nullable
    public static String getLastUserName() {
        return pref.getString(KEY_LAST_USER_NAME,null);
    }

    public static void setIsFirstAlias(boolean isFirstAlias) {
       pref.edit().putBoolean(KEY_IS_FIRST_ALIAS,isFirstAlias).apply();
    }

    public static boolean getIsFirstAlias() {
        return pref.getBoolean(KEY_IS_FIRST_ALIAS,false);
    }

    public static void setLastJobNumber(String lastJobNumber) {
        pref.edit().putString(KEY_LAST_JOB_NUMBER,lastJobNumber).apply();
    }

    public static String getLastJobNumber() {
        return pref.getString(KEY_LAST_JOB_NUMBER,null);
    }

    public static void setIsFirstCourseSignShowGuide(boolean isFirst) {
        pref.edit().putBoolean(KEY_IS_FIRST_COURSE_SIGN_SHOW_GUIDE,isFirst).apply();
    }

    public static boolean getIsFirstCourseSignShowGuide() {
        return pref.getBoolean(KEY_IS_FIRST_COURSE_SIGN_SHOW_GUIDE,true);
    }

    public static void setIsFirstMeetingSignShowGuide(boolean isFirst) {
        pref.edit().putBoolean(KEY_IS_FIRST_MEETING_SIGN_SHOW_GUIDE,isFirst).apply();
    }

    public static boolean getIsFirstMeetingSignShowGuide() {
        return pref.getBoolean(KEY_IS_FIRST_MEETING_SIGN_SHOW_GUIDE,true);
    }

    public static void setNetTimeDifference(Long timeDifference) {
        pref.edit().putLong(KEY_NET_TIME_DIFFERENCE,timeDifference).apply();
    }

    public static Long getNetTimeDifference() {
        return pref.getLong(KEY_NET_TIME_DIFFERENCE,-1);
    }

    public static void isCollectMobileInfo(boolean isCollect){
        pref.edit().putBoolean(KEY_COLLECT_MOBILE_INFO,isCollect).apply();
    }

    public static boolean isCollectMobileInfo(){
        return pref.getBoolean(KEY_COLLECT_MOBILE_INFO,false);
    }

    public static void setChooseThemeType(Integer themeType) {
        pref.edit().putInt(KEY_CHOOSE_THEME_TYPE,themeType).apply();
    }

    public static Integer getChooseThemeType() {
        return pref.getInt(KEY_CHOOSE_THEME_TYPE,0);
    }

    public static void setCurrentRemoteHost(String remoteHostJson) {
        pref.edit().putString(KEY_CURRENT_REMOTE_HOST,remoteHostJson).apply();
    }

    public static String getCurrentRemoteHost() {
        return pref.getString(KEY_CURRENT_REMOTE_HOST,"");
    }

    public static void setIsLoginEaseIm(boolean isLoginEaseIm) {
        pref.edit().putBoolean(KEY_IS_LOGIN_EASE_IM,true).apply();
    }

    public static boolean getIsLoginEaseIm() {
        return pref.getBoolean(KEY_IS_LOGIN_EASE_IM,false);
    }

    public static void setIsFirstShowImg(boolean isShowImgTips) {
        pref.edit().putBoolean(KEY_IS_FIRST_SHOW_IMG,isShowImgTips).apply();
    }

    public static boolean getIsFirstShowImg() {
        return pref.getBoolean(KEY_IS_FIRST_SHOW_IMG,false);
    }

    public static void setFirstAudio(boolean isFirst) {
        pref.edit().putBoolean(KEY_IS_FIRST_AUDIO, isFirst).apply();
    }

    public static boolean isFirstAudio() {
        return pref.getBoolean(KEY_IS_FIRST_AUDIO, true);
    }

    public static void setRandomInt(int randomInt) {
        pref.edit().putInt(KEY_RANDOM_INT, randomInt).apply();
    }

    public static Integer getRandomInt() {
        return pref.getInt(KEY_RANDOM_INT, 0);
    }

    public static void setWebDate(String date) {
        pref.edit().putString(KEY_WEB_NET_DATE, date).apply();
    }

    public static String getWebDate() {
        return pref.getString(KEY_WEB_NET_DATE, "");
    }

    public static void setPermissionAmount(int num) {
        pref.edit().putInt(KEY_PERMISSION_AMOUNT, num).apply();
    }

    public static int getPermissionAmount() {
        return pref.getInt(KEY_PERMISSION_AMOUNT, 0);
    }

    public static void setExpiresLoginTime(long time) {
        pref.edit().putLong(KEY_EXPIRES_LOGIN_TIME, time).apply();
    }

    public static long getExporesLoginTime() {
        return pref.getLong(KEY_EXPIRES_LOGIN_TIME, 0);
    }

    public static void setLastPassword(String password) {
        pref.edit().putString(KEY_LAST_PASSWORD, password).apply();
    }

    public static String getLastPassword() {
        return pref.getString(KEY_LAST_PASSWORD, "");
    }
}
